package com.example.keli.ui.home.adapter;

import android.support.v4.content.ContextCompat;
import android.support.v7.widget.CardView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.keli.R;
import com.example.keli.base.utils.GlideUtil;
import com.example.keli.ui.home.model.DetailUserData;
import com.example.keli.ui.userinfo.UserInfoDialog;

import java.util.List;

/**
 * description:贡献榜单
 * author: Allen
 * date: 2019/3/19 11:51
 */
public class UserListAdapter extends BaseQuickAdapter<DetailUserData.UserInfoBean, BaseViewHolder> {

    public UserListAdapter(List<DetailUserData.UserInfoBean> mData) {
        super(R.layout.item_user_list, mData);
    }

    @Override
    protected void convert(BaseViewHolder helper, final DetailUserData.UserInfoBean mListBean) {
//        helper.setText(R.id.nick_name, mListBean.getNickname());
//        helper.setText(R.id.num, mListBean.getNum()+"次");
//        ImageView avatar = helper.getView(R.id.avatar);
//        GlideUtil.displayCircle(avatar.getContext(), avatar, mListBean.getAvatar());
        helper.setText(R.id.nick_name, mListBean.getNickname());
        helper.setText(R.id.num, mListBean.getNum() + "次");
        ImageView avatar = helper.getView(R.id.avatar);
        ImageView icon = helper.getView(R.id.icon);
        CardView layout = helper.getView(R.id.layout);
        TextView tv_rank = helper.getView(R.id.tv_rank);
        GlideUtil.displayCircle(avatar.getContext(), avatar, mListBean.getAvatar());
        int position = helper.getLayoutPosition();
        icon.setVisibility(View.VISIBLE);
        tv_rank.setText("");
        if (position == 0) {
            layout.setCardBackgroundColor(ContextCompat.getColor(layout.getContext(), R.color.one_bg));
            icon.setImageResource(R.mipmap.one_icon);
        } else if (position == 1) {
            layout.setCardBackgroundColor(ContextCompat.getColor(layout.getContext(), R.color.two_bg));
            icon.setImageResource(R.mipmap.two_icon);
        } else if (position == 2) {
            layout.setCardBackgroundColor(ContextCompat.getColor(layout.getContext(), R.color.three_bg));
            icon.setImageResource(R.mipmap.three_icon);
        } else {
            layout.setCardBackgroundColor(ContextCompat.getColor(layout.getContext(), R.color.white));
            icon.setVisibility(View.GONE);
            tv_rank.setText("NO." + (position + 1));
        }

        avatar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new UserInfoDialog(mContext, mListBean.getUid()).show();
            }
        });
    }

}
